<?php
class Admin_Form_ValidateAmenu{

	private $_arrError;
	
	private $_arrData;
	
	public function __construct($arrParam = null, $options = null){
		
		/*=======================================================
		 * Start - validate name
		 *=======================================================*/	
		$validator = new Zend_Validate();
		
		$pattern = '#^[a-zA-Z0-9\s\.\'\-]+$#';
		$validator->addValidator(new Zend_Validate_NotEmpty(),true)
				  //->addValidator(new Zend_Validate_Alnum(true),true)
				  ->addValidator(new Zend_Validate_Regex($pattern),true)
				  ->addValidator(new Zend_Validate_StringLength(array('min'=>3,'max'=>50,'encoding'=>'utf-8')),true);
				  
		$filter = new Zendvn_Filter_Username();
		$name = $filter->filter($arrParam['name']);
		
		if(!$validator->isValid(trim($name))){
			$message = $validator->getMessages();
			$this->_arrError['name'] = current($message);
			$arrParam['name'] = '';
		}
		
		
		
		/*=======================================================
		 * Start - validate mtype
		 *=======================================================*/	
		
		$validator = new Zend_Validate();
			
		$pattern = '#^[a-zA-Z0-9\-]+$#';
		$validator->addValidator(new Zend_Validate_NotEmpty(),true)
				  ->addValidator(new Zend_Validate_Regex($pattern),true)
				  ->addValidator(new Zend_Validate_StringLength(array('min'=>3,'max'=>100,'encoding'=>'utf-8')),true);
					  
		if($arrParam['area'] == 'admin' || $arrParam['area'] == 'public'  ){
				
			if(!$validator->isValid(trim($arrParam['mModule']))){
				$message = $validator->getMessages();
				$this->_arrError['mModule'] = current($message);
				$arrParam['mModule'] = '';
			}	  
				
			if(!$validator->isValid(trim($arrParam['mController']))){
				$message = $validator->getMessages();
				$this->_arrError['mController'] = current($message);
				$arrParam['mController'] = '';
			}

			if(!$validator->isValid(trim($arrParam['mAction']))){
				$message = $validator->getMessages();
				$this->_arrError['mAction'] = current($message);
				$arrParam['mAction'] = '';
			}
			
		}
		
		if($arrParam['area'] == 'public' ){
				
			if(!$validator->isValid(trim($arrParam['sModule']))){
				$message = $validator->getMessages();
				$this->_arrError['sModule'] = current($message);
				$arrParam['sModule'] = '';
			}	  
				
			if(!$validator->isValid(trim($arrParam['sController']))){
				$message = $validator->getMessages();
				$this->_arrError['sController'] = current($message);
				$arrParam['sController'] = '';
			}

			if(!$validator->isValid(trim($arrParam['sAction']))){
				$message = $validator->getMessages();
				$this->_arrError['sAction'] = current($message);
				$arrParam['sAction'] = '';
			}
		}
		
		$this->_arrData = $arrParam;
	}
	
	public function getData(){
		return $this->_arrData;
	}
	//return true|false
	public function isVaild(){
		$flag = false;
		if(count($this->_arrError) > 0){
			$flag = true;
		}
		return $flag;
	}
	
	public function getMessageErrors(){
		return $this->_arrError;
	}
	
	
}







